#!/bin/bash
#    Copyright (C) 2017  Jonathan Jason Dennis [Meticulus]
#					theonejohnnyd@gmail.com
#
#    This program is free software: you can redistribute it and/or modify
#    it under the terms of the GNU Affero General Public License as
#    published by the Free Software Foundation, either version 3 of the
#    License, or (at your option) any later version.
#
#    This program is distributed in the hope that it will be useful,
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#    GNU Affero General Public License for more details.
#
#    You should have received a copy of the GNU Affero General Public License
#    along with this program.  If not, see <http://www.gnu.org/licenses/>.

RED='\e[31m'
YELLOW='\e[93m'
WHITE='\e[97m'
BOLD='\e[1m'
NORM='\e[0m'

checkerror() {
    if [[ ${1} -gt 0 ]]; then
	if [[ "${3}" == "-fatal" ]]; then
		echo -e "$RED[$(basename ${0})]: ERROR: ${2}$WHITE" >&2
		exit 9
	else
		echo -e "$YELLOW[$(basename ${0})]: WARNING: ${2}$WHITE" >&2	
	fi
    fi
}

mecho(){
    echo -e "$WHITE[$(basename ${0})]: ${1}"
}

sendAdminMail () {
    printf "Subject:$(date): ${1}\n\n${2}" | /usr/sbin/sendmail -f kitchen3@meticulus-development.com theonejohnnyd@gmail.com
}

trimdotslash() {
	DOTSLASH="./"
	PATH=${1}
	echo "${PATH#$DOTSLASH}"
}

findfirstfile() {
	for LINE in $(find ${1} -maxdepth 1 -name ${2})
	do
		echo $LINE
		break
	done
}

getTop() {
  while [[ ! -e .repo ]];
    do
	cd ../

    	if [[ "$PWD" == "/" ]]; then
          checkerror 1 "\$TOP not found!\;Abort!"
        exit 9
    	fi
    done

    echo $PWD
}
